<template>
	<!-- 添加弹框 -->
	<el-dialog width="600px" title="" visible :show-close="false" :modal-append-to-body="false" class="wrap" @close="cancel" :close-on-click-modal="false">
		<i class="el-icon-close close" @click="cancel" style="color: white;"></i>
		<div class="bt">添加学生资料</div>
		<el-form label-width="130px" class="form">
			<el-form-item label="段落名称" >
				<el-input v-model="title" style='width: 250px;' placeholder="" icon="add"  ></el-input>
			</el-form-item>
			<el-form-item label="段落类型" >
				<el-select v-model="lx" style='width: 250px;' @change='getlx()'>
					<el-option label="纯文本" value="wb"></el-option>
					<el-option label="单图" value="tp"></el-option>
					<el-option label="轮播图" value="lbt"></el-option>
					<el-option label="视频" value="sp"></el-option>
					<el-option label="音频" value="yp"></el-option>
					<el-option label="表单" value="tab"></el-option>
				</el-select>
			</el-form-item>
		</el-form>
	      <FwbComponent :params="this.params" v-if='showwb'  @close="componentsHide"></FwbComponent>
	      <TpComponent :params="this.params"  v-if='showtp'  @close="componentsHide"></TpComponent>
	      <LbtComponent :params="this.params" v-if='showlbt' @close="componentsHide" ></LbtComponent>
	      <BdComponent :params="this.params"  v-if='showlbd' @close="componentsHide" ></BdComponent>
		  
	</el-dialog>
</template>
<script type="text/javascript">
	import BqComponent from '../../admin/xxjbszManage/bq'
	import qs from 'qs'
  	import FwbComponent from './fwb'
  	import TpComponent from './tp'
  	import LbtComponent from './lbt'
  	import BdComponent from './bd'
	
	export default {
		props: ['params'],
		components: {
			TpComponent,
			FwbComponent,
			BqComponent,
			LbtComponent,
			BdComponent,
		},
		data() {
			return {
				showwb:true,
				showtp:false,
				showlbt:false,
				showlbd:false,
				datelist:'',
				xwid:this.$route.query.iid,
				lx: '',
				id:'',
				title:'',
				btlist:'',
				content:''
			}
		},
		 computed: {
		   editor() {
		    return this.$refs.myQuillEditor.quill
		   }
		  },
		created() {
//			alert(this.params)
		 	this.btlist = this.params
		 	this.lx = this.btlist.lx
		 	this.title = this.btlist.bt
		 	this.content = this.btlist.nr
		 	this.id = this.btlist.id
		 	if(this.lx == 'wb'){
				this.showwb = true
			}else if(this.lx == 'tp'){
				this.showtp = true
			}else if(this.lx == 'lbt'){
				this.showlbt = true
			}
		},
		methods: {
			getlx(){
				if(this.lx == 'wb'){
					this.showwb = true
					this.showtp = false
					this.showlbt = false
					this.showlbd = false
				}
				if(this.lx == 'tp'){
					this.showwb = false
					this.showtp = true
					this.showlbt = false
					this.showlbd = false
				}
				if(this.lx == 'lbt'){
					this.showwb = false
					this.showtp = false
					this.showlbt = true
					this.showlbd = false
				}
				if(this.lx == 'tab'){
					this.showwb = false
					this.showtp = false
					this.showlbt = false
					this.showlbd = true
				}
			},
			submit() {
				this.$store.state.loading = true;
				var logininfo = JSON.parse(localStorage.logininfo);
				var params3 = qs.stringify({
					issc:'N',
					bt:this.title,
					nr:this.content,
					id:this.id,
					lx:this.lx,
					yhid: logininfo.id,
					xxid: logininfo.xxid,
				});
				//执行
				this.axios.post(this.$store.state.api + 'yxxwdl/update', params3)
					.then(res => {
						if(res.data.code == 1) {
							this.$emit('close', {
								type: 'add',
								cancel: false
							});
							this.$store.state.loading = false;
						} else {
							this.$emit('close', {
								type: 'add',
								cancel: false
							});
							this.$store.state.loading = false;
						}
					}).catch(res => {
						this.$message.warning("服务器繁忙，请重试");
						this.$store.state.loading = false;
					})
			},

			cancel() {
				this.$emit('close', {
					type: 'add',
					cancel: true
				})
			},
			componentsShow(type, data) { //显示组件
				console.log(type, data)
				for(let i in this.portComponents) {
					if(type == this.portComponents[i].type) {
						this.portComponents[i].toggle = true;
						this.portComponents[i].params = data;
						return;
					}
				}
			},
			componentsHide(setting) { //关闭组件
				console.log(setting,999)
				if(setting.type == 'fwb'){
					this.content ='<div>'+setting.list+'</div>'
					this.submit()
				}else if(setting.type == 'tp'){
//					this.content = setting.list
					this.content = '<div><img src="'+setting.list+'"/></div>' 
					this.submit()
				}else if(setting.type == 'lbt'){
//					var urls = setting.list
//					var aa =''
//					for(var i in urls){
//						aa += '<el-carousel-item  :key="'+urls[i]+'"><img src="'+urls[i]+'"/></el-carousel-item>'
//					}
//					alert(aa)
//					this.content = 
//					'<el-carousel height="150px">'+aa+'</el-carousel>'
//					this.submit()
				}else if(setting.type == 'bd'){
					this.content = setting.list+''
					console.log(this.content)
					this.submit()
				}
				
			}
		}
	}
</script>
<style lang="less" scoped>
	.wrap {
		.row {
			height: 50px;
			line-height: 50px;
		}
		.bt {
			position: absolute;
			width: 100%;
			height: 50px;
			margin: 0 auto;
			top: 0;
			left: 0;
			// margin-top: -70px;
			background: #50BFFF;
			// margin-left: -20px;
			// margin-bottom: 20px;
			color: white;
			text-align: left;
			line-height: 50px;
			font-size: 17px;
			padding-left: 15px;
		}
		.close {
			z-index: 10;
			position: absolute;
		}
		.input-block {
			margin-bottom: 20px;
			text-align: center;
		}
		.input {
			width: 280px;
			display: inline-block;
			margin-left: 10px;
		}
		.input1 {
			width: 210px;
			display: inline-block;
			margin-left: 10px;
		}
		.input-block span {
			display: inline-block;
			width: 70px;
			text-align: right;
		}
		.submit {
			width: 120px;
			display: block;
			// float: left;
			margin: 0 auto;
			margin-top: 20px;
		}
		.wpfl {
			// background: red;
			// position: absolute;
			// top: 20%;
			// left: -10%;
		}
		.lskb {
			width: 130%;
			background: #fff;
			position: absolute;
			top: 5px;
			left: -66px;
			z-index: 50;
		}
		.wpfl1 {
			width: 130%;
			background: #fff;
			position: absolute;
			top: 5px;
			left: -66px;
		}
		.form {
			text-align: left;
			margin-top: 20px;
			.select-block {
				width: 45%;
				// display: block;
			}
			.select-block1 {
				width: 68%;
				// display: block;
			}
			.weekdiv {
				width: 100%;
				height: 100%;
				margin: 0 auto;
				background: lightblue;
			}
			.wdiv0 {
				line-height: 45px;
				width: 100px;
				height: 300px;
				float: left;
				background: lightgoldenrodyellow;
			}
			.wdiv1 {
				width: 40px;
				height: 300px;
				float: left;
				background: lightgoldenrodyellow;
			}
			.wdiv2 {
				width: 40px;
				height: 300px;
				float: left;
				background: lightgoldenrodyellow;
			}
			.wdiv3 {
				width: 40px;
				height: 300px;
				float: left;
				background: lightgoldenrodyellow;
			}
			.wdiv4 {
				width: 40px;
				height: 300px;
				float: left;
				background: lightgoldenrodyellow;
			}
			.wdiv5 {
				width: 40px;
				height: 300px;
				float: left;
				background: lightgoldenrodyellow;
			}
			.wdiv6 {
				width: 40px;
				height: 300px;
				float: left;
				background: lightgoldenrodyellow;
			}
			.wdiv7 {
				width: 40px;
				height: 300px;
				float: left;
				background: lightgoldenrodyellow;
			}
			.el-checkbox+.el-checkbox {
				margin-left: 0px;
			}
		}
	}
</style>